Skip to content

Fix process group termination: always send SIGKILL after SIGTERM#151

Merged
jendrikseipp merged 4 commits into
mainfrom
fix-kill-process-group
May 2, 2026
Merged

Fix process group termination: always send SIGKILL after SIGTERM#151
jendrikseipp merged 4 commits into
mainfrom
fix-kill-process-group

Conversation

@TravisRiveraPetit
Copy link
Copy Markdown
Contributor

Fixes an issue in Call._terminate_process_group where SIGKILL was only sent if the parent process was still alive.

Comment thread lab/calls/call.py
os.killpg(os.getpgid(self.process.pid), signal.SIGKILL)

with contextlib.suppress(OSError, ProcessLookupError):
os.killpg(pgid, signal.SIGKILL)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for this change? I don't think it's good style to kill a process that we know has terminated. Is poll not reliable? If the process has terminated, it will be in zombie state here. Better to have it finish normally than kill it, I would say, if it has terminated in the one-second grace period.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that we are currently using poll() on the leader process as a proxy for whether the whole process group has terminated.

Before, if the leader spawned child processes, it could happen that the leader exited after SIGTERM while some children were still running. In that case, poll() would return the leader’s exit code rather than None.

@jendrikseipp
Copy link
Copy Markdown
Collaborator

Thanks for looking into this! Claude and I added some code for avoiding killing processes that are already dead as suggested by Malte.

@jendrikseipp jendrikseipp merged commit 968b971 into main May 2, 2026
10 checks passed
@jendrikseipp jendrikseipp deleted the fix-kill-process-group branch May 2, 2026 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants